<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Overview - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.memory.overview.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.memory.overview.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.memory.html">Zend_Memory</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.memory.html">Zend_Memory</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.memory.memory-manager.html">Memory Manager</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.memory.overview" class="section"><div class="info"><h1 class="title">Overview</h1></div>
    

    <div class="section" id="zend.memory.introduction"><div class="info"><h1 class="title">Introduction</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Memory</span> component is intended to manage data in an
            environment with limited memory.
        </p>

        <p class="para">
            Memory objects (memory containers) are generated by memory manager
            by request and transparently swapped/loaded when it&#039;s necessary.
        </p>

        <p class="para">
            For example, if creating or loading a managed object would cause
            the total memory usage to exceed the limit you specify, some
            managed objects are copied to cache storage outside of memory.
            In this way, the total memory used by managed objects does not
            exceed the limit you need to enforce.
        </p>

        <p class="para">
            The memory manager uses
            <a href="zend.cache.backends.html" class="link">Zend_Cache backends</a>
            as storage providers.
        </p>

        <div class="example" id="zend.memory.introduction.example-1"><div class="info"><p><b>Example #1 Using Zend_Memory component</b></p></div>
            

            <div class="example-contents"><p>
                 <span class="methodname">Zend_Memory::factory()</span> instantiates the memory
                manager object with specified backend options.
            </p></div>

            <pre class="programlisting brush: php">
$backendOptions = array(
    &#039;cache_dir&#039; =&gt; &#039;./tmp/&#039; // Directory where to put the swapped memory blocks
);

$memoryManager = Zend_Memory::factory(&#039;File&#039;, $backendOptions);

$loadedFiles = array();

for ($count = 0; $count &lt; 10000; $count++) {
    $f = fopen($fileNames[$count], &#039;rb&#039;);
    $data = fread($f, filesize($fileNames[$count]));
    $fclose($f);

    $loadedFiles[] = $memoryManager-&gt;create($data);
}

echo $loadedFiles[$index1]-&gt;value;

$loadedFiles[$index2]-&gt;value = $newValue;

$loadedFiles[$index3]-&gt;value[$charIndex] = &#039;_&#039;;
</pre>

        </div>
    </div>

    <div class="section" id="zend.memory.theory-of-operation"><div class="info"><h1 class="title">Theory of Operation</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Memory</span> component operates with the following concepts:

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">Memory manager</p>
                </li>

                <li class="listitem">
                    <p class="para">Memory container</p>
                </li>

                <li class="listitem">
                    <p class="para">Locked memory object</p>
                </li>

                <li class="listitem">
                    <p class="para">Movable memory object</p>
                </li>
            </ul>
        </p>

        <div class="section" id="zend.memory.theory-of-operation.manager"><div class="info"><h1 class="title">Memory manager</h1></div>
            

            <p class="para">
                The memory manager generates memory objects (locked or movable)
                by request of user application and returns them wrapped into
                a memory container object.
            </p>
        </div>

        <div class="section" id="zend.memory.theory-of-operation.container"><div class="info"><h1 class="title">Memory container</h1></div>
            

            <p class="para">
                The memory container has a virtual or actual <span class="property">value</span>
                attribute of string type. This attribute contains the data value
                specified at memory object creation time.
            </p>

            <p class="para">
                You can operate with this <span class="property">value</span> attribute as
                an object property:
            </p>

            <pre class="programlisting brush: php">
$memObject = $memoryManager-&gt;create($data);

echo $memObject-&gt;value;

$memObject-&gt;value = $newValue;

$memObject-&gt;value[$index] = &#039;_&#039;;

echo ord($memObject-&gt;value[$index1]);

$memObject-&gt;value = substr($memObject-&gt;value, $start, $length);
</pre>


            <blockquote class="note"><p><b class="note">Note</b>: 
                <p class="para">
                    If you are using a <acronym class="acronym">PHP</acronym> version earlier than 5.2, use the
                    <a href="zend.memory.memory-objects.html#zend.memory.memory-objects.api.getRef" class="link">getRef()</a>
                    method instead of accessing the value property directly.
                </p>
            </p></blockquote>
        </div>

        <div class="section" id="zend.memory.theory-of-operation.locked"><div class="info"><h1 class="title">Locked memory</h1></div>
            

            <p class="para">
                Locked memory objects are always stored in memory.
                Data stored in locked memory are never swapped to the cache
                backend.
            </p>
        </div>

        <div class="section" id="zend.memory.theory-of-operation.movable"><div class="info"><h1 class="title">Movable memory</h1></div>
            

            <p class="para">
                Movable memory objects are transparently swapped and loaded
                to/from the cache backend by <span class="classname">Zend_Memory</span> when it&#039;s necessary.
            </p>

            <p class="para">
                The memory manager doesn&#039;t swap objects with size less than
                the specified minimum, due to performance considerations.
                See <a href="zend.memory.memory-manager.html#zend.memory.memory-manager.settings.min-size" class="link">this section</a>
                for more details.
            </p>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.memory.html">Zend_Memory</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.memory.html">Zend_Memory</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.memory.memory-manager.html">Memory Manager</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.memory.html">Zend_Memory</a></li>
  <li class="active"><a href="zend.memory.overview.html">Overview</a></li>
  <li><a href="zend.memory.memory-manager.html">Memory Manager</a></li>
  <li><a href="zend.memory.memory-objects.html">Memory Objects</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>